using System;
using Comdiv.Extensions;
using Comdiv.Model.Mapping;
using FluentNHibernate;
using NHibernate.Cfg;
using NHibernate.Dialect;

namespace Comdiv.Persistence.Tests{
    public class simplemodel:PersistenceModel,IConfigurationBoundedModel{
        private string dbspec;

        public simplemodel(string dbspec){
            this.dbspec = dbspec;
            Add(new simpleMap(dbspec));
        }

        public bool IsFor(Configuration cfg){
            if (dbspec.noContent()) return true;
            if (dbspec=="sqllite"){
                return typeof(SQLiteDialect).IsAssignableFrom(Dialect.GetDialect(cfg.Properties).GetType());
            }
            if(dbspec=="postgres"){
                return typeof(PostgreSQLDialect).IsAssignableFrom(Dialect.GetDialect(cfg.Properties).GetType());
            }
            return Dialect.GetDialect(cfg.Properties).GetType().Name.ToUpper().Contains(dbspec.ToUpper());
        }
    }
}